package net.com.hydroPK;

import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileNotFoundException;

/**
 * File created by: Joshua
 * Created on 16/2/2010 at 12:30
 */
public class DoorHandler {
    public static int[] doorFace = new int[1000];
    public static int[] doorFaceClosed = new int[1000];
    public static int[] doorFaceOpen = new int[1000];
    public static int[] doorHeight = new int[1000];
    public static int[] doorId = new int[1000];
    public static int[] doorState = new int[1000];
    public static int[] doorX = new int[1000];
    public static int[] doorY = new int[1000];
    public static long[] doorClicked = new long[1000];

    public DoorHandler() {
        try {
            loadDoors();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public boolean loadDoors() {
        String line;
        String token;
        String token2;
        String token2_2;
        String[] token3;
        boolean EndOfFile = false;
        int doorCount = 0;
        BufferedReader reader;
        try {
            reader = new BufferedReader(new FileReader("./data/doors.cfg"));
        } catch (FileNotFoundException fileex) {
           System.out.println("[LOAD DOORS] File not found.");
            return false;
        }
        try {
            line = reader.readLine();
        } catch (IOException ioexception) {
            System.out.println("[LOAD DOORS] Error loading file.");
            return false;
        }
        while ((!EndOfFile) && (line != null)) {
            line = line.trim();
            int spot = line.indexOf("=");
            if (spot > -1) {
                token = line.substring(0, spot);
                token = token.trim();
                token2 = line.substring(spot + 1);
                token2 = token2.trim();
                token2_2 = token2.replaceAll("\t\t", "\t");
                token2_2 = token2_2.replaceAll("\t\t", "\t");
                token2_2 = token2_2.replaceAll("\t\t", "\t");
                token2_2 = token2_2.replaceAll("\t\t", "\t");
                token2_2 = token2_2.replaceAll("\t\t", "\t");
                token3 = token2_2.split("\t");
                if (token.equals("door")) {
                    doorX[doorCount] = Integer.parseInt(token3[0]);
                    doorY[doorCount] = Integer.parseInt(token3[1]);
                    doorId[doorCount] = Integer.parseInt(token3[2]);
                    doorFaceOpen[doorCount] = Integer.parseInt(token3[3]);
                    doorFaceClosed[doorCount] = Integer.parseInt(token3[4]);
                    doorFace[doorCount] = Integer.parseInt(token3[5]);
                    doorState[doorCount] = Integer.parseInt(token3[6]);
                    doorHeight[doorCount] = Integer.parseInt(token3[7]);
                    doorClicked[doorCount] = 0;
                    doorCount++;
                }
            }
            try {
                line = reader.readLine();
            } catch (IOException ioexception1) {
                EndOfFile = true;
            }
        }
        try {
            reader.close();
        } catch (IOException ioexception) { }
        return false;
    }
}
